In this lesson we're going to set up 10 support tensor board is going to run locally on our machine
and it's going to allow us to track how our training is going.
Our model is doing how it's evolving and learning as the training progresses and it allows us to easily
compare different models and their performance.
Now if you're following along using Google collaborate try notebooks.
This lesson is going to be a lot less relevant.
And you're welcome to skip it but if you're running this locally on your machine like the way I am.
Then follow along with me.
Let's insert a markdown cell here that's going to read tensor board and maybe parentheses visualizing
learning that we were going to set up tents board is going to require a couple of steps.
So tensor board is going to read and write to our disk to our hard disk and it's going to need to know
where to read and write its files.
So what we're gonna do is we're going to set up a special folder for all the files that tensor board
is going to use on our machine and we're gonna set up this folder programmatically in our Jupiter notebook.
So scroll back up to your inputs and there you should see.
Import os if you haven't got this added now and can add a couple of more import statements.
For starters Rasch going to import 10 support.
So from Caris don't callbacks import tensor board.
The second thing that we're gonna import is a handy function from the time module so we'll see from
time import s t r f time.
This will give us a very quick way of getting the hour and the minute of the current time.
And you're gonna see how we're going to use this in a minute as well.
So shift enter on the cell and scroll back down to your constants and we're going to add the folder
name that we're going to create.
So we'll call this constant log on underscore score Diaw directory is equal to single quotes tensor
board underscore C I F A R on the score logs and then we'll put a forward slash at the end we will shortly
create this folder here in a side project folder.
So let's hit shift enter on our constants scroll back down to where we're gonna be setting up tents
aboard and let's write our code for our Folder creation.
The first thing that we're gonna decide on is a folder name so check it out folder on a school name
it's gonna be equal to and here will provide a string.
So it'll be an F string.
So let's call it model on a score one at.
And here we're gonna add some curly braces and we're gonna get the current our.
And the current minute for the time.
So we're gonna use that s t r f time function and we're going to open some parentheses inside.
And here we're gonna use double quotes and then we'll have % h space percent.
And now if this looks very mysterious to you.
Let's print this out so print folder on a score name and you'll see what this does.
So if I had shift enter on the cell right now you'll see the string model on a square one at 17 0 6.
So if you look up here at my time it's Monday 5 0 6.
Where am I going with this.
Well I want the current time to be included in my folder name because if I run my code more than once
then I'll get different sub folders setup.
Every time I run my model and this allows me to keep track of what I'm doing and what's going on.
Now I'm actually not going to force you to use the same convention that I'm using him for naming my
folders if you'd like to pull out a different value from that current time then head over to the documentation
for SDR f time.
This is built in into python and scroll down here to this table and here you can see what the different
parameters are that you can pull out.
So I've pulled out % h the 24 hour clock time alongside with capital and the minute the zero pad a decimal
number.
Now if you want to pull out the second as well you can do that with percent s and if you wanted to pull
out the weekday or the month then these are the parameters that you want to use.
So if you want to play around with this a little bit then pause the video and give this a go see what
you can pull out.
Otherwise let's delete this line here and let's actually create our directory.
So the way we're gonna do this is with our OS module operating system OS dot path.
Don't join.
We'll create our folder path for us.
So what are we going to join.
We're going to join our root directory our log underscored directory from upstairs in the constant section
alongside with our folder name.
So this will create a path for us.
And with this path we can actually make a directory including a sub directory so setting up two folders
in a row the way we're gonna do this is with OS.
Don't make D.
IRS make directories and this will need a path.
In other words this value should actually go between these parentheses.
So you can see that the paths are quite important.
So let's give them their own variable to make this code a lot easier and less nested Diaw are underscore
paths and we'll put that in here.
Are on a score paths.
Now what I'll do is I'll make this window slightly smaller and bring up my project folder here on the
side so you can see what happens as I execute this cell.
Did you spot it.
Here's my tensor board on a score CFR underscore logs folder and then inside this folder.
Got a sub folder called model on a score one at seventeen twelve brilliant right.
Let's see what happens when I execute the cell again in this case.
I've got an error my code just failed.
If I scroll down I can see why.
Error number seventeen file exists.
Python did not like executing this cell again when the folder already existed.
So if I delete this folder it should work in theory right.
So I deleted it.
Hit shift enter and I get my folder being created in my cell executing without an error.
So how can we make this a little bit more failsafe.
How can we add some code here to handle these errors if there are any.
The python pattern that we're gonna adopt here is the try block.
So if you write try semicolon and then tab this line of code over so that it is nested inside this try
statement here.
Then python will try to execute this code and if it gets an error then it gives us a chance to handle
the error.
So let's do just that on the next line.
Use the keyword except and the except keyword will be followed by the kind of error that we're gonna
get we're gonna get an OS error.
So that's capital O capital S capital E and then we're going to try and print this era.
So first what it will do is we'll store this error as a variable called E R R and then I'll Addy semicolon
here at the end and then in the next line nested inside except I'll print e r r r dot s t r error.
This will convert our error to a string and allow us to print it out.
The very last thing I want to do is I want to write a success message.
If everything worked splendidly so I'll add an else clause here.
This is gonna be at the same level as our try and our except block and all it's gonna do is print out
the message successfully created the rectory.
So what are we doing here.
Well we're going to try to create these folders if we have an error.
We're going to print out the error below the cell and otherwise we're gonna print out success.
That's all we're gonna do.
So let's try this out.
Let's see what happens when I execute the cell create the directory and then execute the cell again.
In this case all that happens is we handle the error and the error rates of file exists.
So no directories are created and there's nothing else we have to do.
Brilliant.
Let me quickly go to you and toggle my head so that I've got a little bit more screen real estate.
Now all we've done so far is talk to her operating system and create some folders.
We actually haven't set up tents aboard yet tense aboard.
It's actually very very simple to setup a hall we need to do is call tense aboard open parentheses and
then inside these parentheses supply the log directory so we need to point ten support to the folder
where those logs are going to live.
So log underscored the IRR is equal to this value right here.
This is where we've created our folders right.
So Diaw on a score path's is the argument that we're going to feed into this call to tend avoid how.
This is very well and good but we actually probably want to create a new folder every time we train
the model because we're training it made with a slight variation or we're trading one or two or three
or four.
So this ideally should be a function and we know of course how to create functions.
We do that with the DFT would we'll call this function get tense a board and we're gonna supply only
one parameter here and it's going to be the model on discordant names so that way we can vary up the
folder name depending on what input this function gets.
So if I had some curly braces here and change this to model on a screen name then the folder name will
be whatever it is that we've supplied to this function and we can take all of this code.
Now tab it over.
So it all moves and it's inside the body of the function and then we will return the 10 support object.
This is all the work that we need to do to get tense board up and running to actually see tensor board
in action will need to train our model though and we're gonna do just that in the next lesson.
I'll see you there.